package com.example.service;

import com.example.entity.State;
import com.example.mapper.StateMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 账单分类业务处理
 **/
@Service
public class StateService {

    @Resource
    private StateMapper stateMapper;

    /**
     * 新增
     */
    public void add(State state) {
        stateMapper.insert(state);
    }

    /**
     * 删除
     */
    public void deleteById(Integer id) {
        stateMapper.deleteById(id);
    }

    /**
     * 批量删除
     */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            stateMapper.deleteById(id);
        }
    }

    /**
     * 修改
     */
    public void updateById(State state) {
        stateMapper.updateById(state);
    }

    /**
     * 根据ID查询
     */
    public State selectById(Integer id) {
        return stateMapper.selectById(id);
    }

    /**
     * 查询所有
     */
    public List<State> selectAll(State state) {
        return stateMapper.selectAll(state);
    }

    /**
     * 分页查询
     */
    public PageInfo<State> selectPage(State state, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<State> list = stateMapper.selectAll(state);
        return PageInfo.of(list);
    }

}